#!/usr/bin/env python
# coding=utf-8
# @FileName  :mkdir_file.py
# @Time      :2024/6/17 22:03
# @Author    :jdz

import os
import shutil

# 指定目录路径
directory = r"D:\Notes\Typora\JavaNotes\my"

# 遍历目录下的所有文件
for filename in os.listdir(directory):
    # 获取文件名和扩展名
    name, extension = os.path.splitext(filename)
    # 如果是文件夹则跳过
    if os.path.isdir(os.path.join(directory, filename)):
        continue
    # 创建同名文件夹
    new_folder = os.path.join(directory, name)
    os.makedirs(new_folder)
    # 将同名文件移动到相应的文件夹中
    old_file = os.path.join(directory, filename)
    new_file = os.path.join(new_folder, filename)
    shutil.move(old_file, new_file)

